Repository navigation
fix(runtime): resolve megaregexp capture refs against the rule's own groups - #135
Merged
Merged
Conversation
…groups WO18 G1 (maps parity audit): a parallel block joined into one alternation wraps each rule in a named group, and the replace callback handed the template resolver the GLOBAL group list - so a ref(1) template in capture-in-parallel rules resolved to the wrapper's whole match instead of the rule's first capture (ax -> axX, k3a -> kk3a). parallelMegaregexp now counts each rule's numbered capture groups (countCaptureGroups mirrors compile-item's group-emission grammar) and hands the replacement only the slice of global groups the matched rule owns, matching rs interpreter semantics. Probe maps from the audit's battery pin the canonical outputs (aX / aXB / 3ka).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WO18 G1 from the maps parity audit:
capture(...)/ref(N)inside aparallelblock produced silently wrong output.The megaregexp join wraps every rule in a named group (
(?<__r0>...)), so the wrapper groups occupy the leading slots of the global numbered-group list. The replace callback then handed that global list to the template resolver, so$1inref(1)resolved to the wrapper's whole match instead of the rule's first capture.Semantics chosen: correct output (rs parity) — the offset math is exact because the pattern grammar is fully controlled by
compile-item.ts(the only capturing construct iscapture_groupcompiled as a bare(...); all other groups are(?:...)or lookarounds). Rejection was unnecessary.Change
src/stdlib.ts:parallelMegaregexpnow computes, per rule, the number of numbered groups its own pattern emits (countCaptureGroups) and hands the replacement only the rule-owned slice of the global group list.docs/parity/probes/maps):ax -> aX,axb -> aXB,k3a -> 3ka.Evidence
Red (before the fix, audit values reproduced exactly):
Green after the fix:
24 passed (24)for the two touched files; fullnpm testshows only pre-existing network-flaky failures (cli/client-work/imf) — the same families fail on a pristineorigin/mainworktree baseline (16 failures there vs 9 here, all network-timeout). Generated-parser, golden and parity suites untouched and green. Grammar files untouched.Test plan
npx vitest run test/stdlib.test.ts test/isc/capture-parallel.test.ts— red before, green afternpm test— no new failures vs origin/main baselinetsc --noEmitandeslintclean